//
//  SSRootViewController.m
//  LawOffice
//
//  Created by SunZhongyuan on 2018/5/11.
//  Copyright © 2018年 SunZhongyuan. All rights reserved.
//

#import "SSRootViewController.h"
#import "SRHomeViewController.h"
#import "SRSportsHomeViewController.h"
#import "SRAskAndAnswerHomeViewController.h"
#import "SRFurtherStudyHomeViewController.h"
#import "SRMyHomeViewController.h"

@interface SSRootViewController ()

@end

@implementation SSRootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 初始化视图控制器
    [self initViewControllers];
    // 初始化标签栏
    [self initTabBar];
}

#pragma mark - private methods
- (void)initViewControllers {
    // 首页
    SRHomeViewController *homeVC = [[SRHomeViewController alloc] initWithTitle:@"" needBack:NO];
    // 运动 - 首页
    SRSportsHomeViewController *sportsVC = [[SRSportsHomeViewController alloc] initWithTitle:@"运动" needBack:NO];
    // 问答解惑 - 首页
    SRAskAndAnswerHomeViewController *askAndAnswerVC = [[SRAskAndAnswerHomeViewController alloc] initWithTitle:@"问答解惑" needBack:NO];
    // 深造 - 首页
    SRFurtherStudyHomeViewController *furtherStudyVC = [[SRFurtherStudyHomeViewController alloc] initWithTitle:@"深造" needBack:NO];
    // 我的 - 首页
    SRMyHomeViewController *myVC = [[SRMyHomeViewController alloc] initWithTitle:@"我的" needBack:NO];
    
    NSArray *vcArr = @[homeVC, sportsVC, askAndAnswerVC, furtherStudyVC, myVC];
    NSMutableArray *tabArr = [[NSMutableArray alloc] initWithCapacity:vcArr.count];
    for (int i = 0; i < vcArr.count; i++) {
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vcArr[i]];
        [tabArr addObject:nav];
    }
    self.viewControllers = tabArr;
}

- (void)initTabBar {
    UITabBar *tabbar = self.tabBar;
    tabbar.backgroundColor = UIColorFromRGB(0XF4FCFF);
    NSArray *titleArr = @[@"首页", @"运动", @"问答解惑", @"深造", @"我的"];
    NSArray *itemArr = @[
                         @{@"selected": @"tab_home_selected", @"normal": @"tab_home"},
                         @{@"selected": @"tab_sports_selected", @"normal": @"tab_sports"},
                         @{@"selected": @"tab_ask_selected", @"normal": @"tab_ask"},
                         @{@"selected": @"tab_further_selected", @"normal": @"tab_further"},
                         @{@"selected": @"tab_my_selected", @"normal": @"tab_my"}];
    for (int i = 0; i < itemArr.count; i++) {
        UITabBarItem *item = [tabbar.items objectAtIndex:i];
        item.title = titleArr[i];
        item.selectedImage = [[UIImage imageNamed:itemArr[i][@"selected"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.image = [[UIImage imageNamed:itemArr[i][@"normal"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0x666666)} forState:UIControlStateNormal];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0x042378)} forState:UIControlStateSelected];
        [item setTitlePositionAdjustment:UIOffsetMake(0, -2.5)];
    }
}



@end
